package com.yuexun.dhdoctor.module.Contract.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.module.Contract.bean.GroupGroupData;

import java.util.ArrayList;

/**
 * Created by work-jx on 2016/7/20.
 */
public class GroupAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<GroupGroupData> mDatas;

    public GroupAdapter(Context context, ArrayList<GroupGroupData> mDatas){
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return null == mDatas ? 0 : mDatas.size();
//        return 7;
    }

    @Override
    public Object getItem(int position) {
        return null == mDatas ? null : mDatas.get(position);
//        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(null == convertView) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_group, parent, false);
            holder = new ViewHolder();
            holder.group_name = (TextView)convertView.findViewById(R.id.item_group_name);
            holder.group_count = (TextView)convertView.findViewById(R.id.item_group_count);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.group_name.setText(mDatas.get(position).getTitle());
        holder.group_count.setText(mDatas.get(position).getToId().size()+"人");

        return convertView;
    }

    class ViewHolder{
        TextView group_name,group_count;

    }
}
